import { save, load, remove } from '@/utils/storage'
import { Difficulty } from "sudoku-gen/dist/types/difficulty.type";

const saveCache = (sudoku: SudokuGame) => {
    const {
        origin, puzzle, solution, difficulty, startTime,
    } = sudoku;
    const obj = {
        origin,
        puzzle,
        solution,
        difficulty,
        duration: new Date().getTime() - startTime,
    };
    save('sudoku', JSON.stringify(obj));
}

const loadCache = async () => {
    const cacheSudoku = load('sudoku');
    if (cacheSudoku) {
        const parse = JSON.parse(cacheSudoku);
        if (parse) {
            const {
                origin,
                puzzle,
                solution,
                difficulty,
                duration,
            } = parse;
            // setOrigin(origin);
            // setPuzzle(puzzle);
            // setSolution(solution);
            // setDifficulty(difficulty);
            // startTime.current = new Date().getTime() - duration;
            // const seconds = duration / 1000;
            // const hms = formatSecondsToHMS(seconds);
            // setGameTime(hms);
            // startTimer();
        }
    }
}

export const CHECK_CONFIG = {
    'begin': 4, 'easy': 3, 'medium': 2, 'hard': 1, 'expert': 0,
}